var e, t = require("../../@babel/runtime/helpers/interopRequireDefault"), a = t(require("../../@babel/runtime/regenerator")), i = t(require("../../@babel/runtime/helpers/asyncToGenerator")), n = require("../../1D8980678A52ABCF7BEFE860FD67FE64.js"), r = require("../../E52ED4948A52ABCF8348BC934D77FE64.js"), s = require("../../3F2EFC058A52ABCF59489402DCA7FE64.js"), u = getApp(), o = null;

Page({
    data: {
        douyin: n.IMGPATH + "but_douyin.png",
        icons: {
            del: n.IMGPATH + "del.png",
            ic_search: n.IMGPATH + "ic_search.png",
            ic_delete: n.IMGPATH + "ic_delete.png",
            ic_hot: n.IMGPATH + "ic_hot.png",
            no: n.IMGPATH + "no.png",
            back: n.IMGPATH + "back.png"
        },
        keyWord: "",
        winHeight: "",
        pageNumber: 1,
        pageSize: 10,
        questionCategory: "",
        list: [],
        fetchDataDone: !1,
        status: !1
    },
    onLoad: function() {
        this.setData({
            winHeight: u.globalData.winHeight - 322
        }), wx.showLoading({
            title: "加载中"
        }), this.fetchData();
    },
    fetchData: (e = (0, i.default)(a.default.mark(function e() {
        var t, i, n, u, o, c, l, d, h, g;
        return a.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return t = !1, i = this.data, n = i.list, u = i.keyWord, o = i.pageNumber, c = i.pageSize, 
                l = i.questionCategory, e.next = 4, (0, r.ajax)({
                    url: "/api/testQuestion/getPager",
                    data: {
                        keyWord: u,
                        pageSize: c,
                        pageNumber: o,
                        questionCategory: l
                    }
                });

              case 4:
                if (d = e.sent, wx.hideLoading(), d.code) {
                    e.next = 16;
                    break;
                }
                if ((h = d.data.data).length) {
                    e.next = 10;
                    break;
                }
                return e.abrupt("return");

              case 10:
                for (h.length >= c && (o++, t = !0), g = 0; g < h.length; g++) h[g].reads = (0, 
                s.getRandomNumberByRange)(1e3, 1e5);
                n = n.concat(h), this.setData({
                    pageNumber: o,
                    list: n,
                    status: t,
                    fetchDataDone: !0
                }), e.next = 17;
                break;

              case 16:
                this.setData({
                    fetchDataDone: !0,
                    status: !1
                });

              case 17:
                return e.abrupt("return", t);

              case 18:
              case "end":
                return e.stop();
            }
        }, e, this);
    })), function() {
        return e.apply(this, arguments);
    }),
    lowerScroll: function(e) {
        this.data.status && this.fetchData();
    },
    backHandle: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    clearHandle: function() {
        var e = this;
        this.setData({
            list: [],
            keyWord: "",
            pageNumber: 1
        }, function() {
            e.fetchData();
        });
    },
    searchHandle: function() {
        var e = this;
        this.data.keyWord && (wx.showLoading({
            title: "搜索中"
        }), this.setData({
            list: [],
            pageNumber: 1
        }, function() {
            e.fetchData();
        }));
    },
    handleInput: function(e) {
        var t = this;
        o && clearTimeout(o), o = setTimeout(function() {
            var a = e.detail.value;
            t.setData({
                keyWord: a
            }, function() {
                a || t.fetchData();
            });
        }, 300);
    },
    handleConfirm: function(e) {
        var t = this, a = e.detail.value;
        this.setData({
            keyWord: a
        }, function() {
            a || t.fetchData();
        });
    },
    jumpDetail: function(e) {
        var t = e.currentTarget.dataset.id;
        if (!t) throw new Error("detail id 缺失");
        wx.navigateTo({
            url: "/pages/detail/index?id=" + t
        });
    }
});